package hust.cs.javacourse.search.run;

import hust.cs.javacourse.search.index.AbstractPosting;
import hust.cs.javacourse.search.index.impl.Posting;
import hust.cs.javacourse.search.index.impl.PostingList;
import hust.cs.javacourse.search.index.impl.Term;
import hust.cs.javacourse.search.query.AbstractHit;
import hust.cs.javacourse.search.query.AbstractIndexSearcher;
import hust.cs.javacourse.search.query.AbstractIndexSearcher.LogicalCombination;
import hust.cs.javacourse.search.query.Sort;
import hust.cs.javacourse.search.query.impl.SimpleSorter;
import hust.cs.javacourse.search.query.impl.IndexSearcher;
import hust.cs.javacourse.search.util.Config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 测试搜索
 */
public class TestSearchIndex {
    /**
     *  搜索程序入口
     * @param args ：命令行参数
     */
    public static void main(String[] args) {
        Sort simpleSorter = new SimpleSorter();
        String indexFile = Config.INDEX_DIR + "index.dat";
        AbstractIndexSearcher searcher = new IndexSearcher();
        searcher.open(indexFile);
        //AbstractHit[] hits = searcher.search(new Term("coronavirus"), simpleSorter);
        AbstractHit[] hits = searcher.search(new Term("state"), new Term("spread"),simpleSorter,
                LogicalCombination.ADN);
        for(AbstractHit hit : hits){
            System.out.println(hit);
        }
//        Integer[] pn1 = {1,2,3,4};
//        List<Integer> pos1 = Arrays.asList(pn1);
//        Integer[] pn2 = {2,4,3,1};
//        List<Integer> pos2 = Arrays.asList(pn2);
//        Integer[] pn3 = {5,6};
//        List<Integer> pos3 = Arrays.asList(pn3);
//
//        PostingList postingList = new PostingList();
//        Posting p1 = new Posting(1,4,pos1);
//        Posting p2 = new Posting(1,4,pos2);
//        Posting p3 = new Posting(2,2,pos3);
//        List<AbstractPosting> pList = new ArrayList<>();
//
//        pList.add(p1);
//        pList.add(p2);
//        pList.add(p3);
//        //postingList.add(pList);
//        postingList.add(p1);
//        postingList.add(p2);
//        postingList.add(p3);
//        //System.out.println(p1.equals(p2));
//        System.out.println(postingList.toString());

    }
}
